package com.daimler.itffo.tables;

import java.util.InputMismatchException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import com.daimler.itffo.uvs.kern.IGenerator;
import com.daimler.itffo.uvs.kern.SQLStatment;
import com.daimler.itffo.uvs.kern.SQLWriter;

public class V0BRB172Type implements IGenerator {

	public static int COL_B172_SO_LAND = 1;
	public static int COL_B172_SO_NR = 2;
	public static int COL_B172_SO_ART = 3;
	public static int COL_B172_FIRMA = 4;
	public static int COL_B172_FIRMA2 = 5;
	public static int COL_B172_FIRMA3 = 6;
	public static int COL_B172_ORT = 7;
	public static int COL_B172_PLZ = 8;
	public static int COL_B172_STRASSE = 9;
	public static int COL_B172_POSTFACH = 10;
	public static int COL_B172_TEL = 11;
	public static int COL_B172_FAX = 12;
	public static int COL_B172_TELEX = 13;
	public static int COL_B172_TEL_PKW = 14;
	public static int COL_B172_TEL_NFZ = 15;
	public static int COL_B172_FAX_PKW = 16;
	public static int COL_B172_FAX_NFZ = 17;
	public static int COL_B172_PART_PKW = 18;
	public static int COL_B172_PART_NFZ = 19;
	public static int COL_B172_PLZ_P = 20;
	public static int COL_B172_PASSWORT = 21;
	public static int COL_B172_EMAIL = 22;
	public static int COL_B172_URL = 23;
	public static int COL_B172_EMAIL_PKW = 24;
	public static int COL_B172_EMAIL_NFZ = 25;
	public static int COL_B172_R2R = 26;
	public static int COL_B172_Q_STANDARD = 27;
	public static int COL_B172_DAT_SEND = 28;
	public static int COL_B172_WW_PASSWORT = 29;
	public static int COL_B172_RETAIL = 30;
	public static int COL_B172_UNTERN = 31;
	public static int COL_B172_STILL_KZ = 32;
	public static int COL_B172_DAT_SEND_ONL = 33;
	public static int COL_B172_TEL_TRAPO = 34;
	public static int COL_B172_FAX_TRAPO = 35;
	public static int COL_B172_EMAIL_TRAPO = 36;
	public static int COL_B172_DEALER_TYPE = 37;
	public static int COL_B172_IS_RETAIL = 38;
	public static int COL_B172_IS_WHOLES = 39;
	public static int COL_B172_GPS_X = 40;
	public static int COL_B172_GPS_Y = 41;
	public static int COL_B172_REGION = 42;
	public static int COL_B172_DSC_LEV_SMART = 43;
	public static int COL_B172_DSC_LEV_MB = 44;
	public static int COL_B172_DSC_LEV_TRUCK = 45;
	public static int COL_B172_DSC_LEV_VAN = 46;
	public static int COL_B172_SUB_TYP = 47;
	public static int COL_B172_MPC_NR = 48;
	public static int COL_B172_GSSN_ID = 49;
	public static int COL_B172_GSSN_TIMEST = 50;
	public static int COL_B172_MAN_PFLEGE = 51;
	public static int COL_B172_PART_TRAPO = 52;
	public static int COL_B172_CPO = 53;
	public static int COL_B172_IS_OWN_RETAIL = 54;
	public static int COL_B172_MASTER_SO_NR = 55;
	public static int COL_B172_RELATED_TO_GSSN_ID = 56;
	public static int COL_B172_TAX_ID = 57;
	public static int COL_B172_VAT_NO = 58;
	public static int COL_B172_DEBITOR_ACCOUNT = 59;
	private String messages = new String("");
	// private String SO_LAND;
	// private String SO_NR;
	private String SO_ART;
	private String FIRMA;
	private String FIRMA2;
	private String FIRMA3;
	private String ORT;
	private String PLZ;
	private String STRASSE;
	private String POSTFACH;
	private String TEL;
	private String FAX;
	private String TELEX;
	private String TEL_PKW;
	private String TEL_NFZ;
	private String FAX_PKW;
	private String FAX_NFZ;
	private String PART_PKW;
	private String PART_NFZ;
	private String PLZ_P;
	private String PASSWORT;
	private String EMAIL;
	private String URL;
	private String EMAIL_PKW;
	private String EMAIL_NFZ;
	private String R2R;
	private String Q_STANDARD;
	private String DAT_SEND;
	private String WW_PASSWORT;
	private String RETAIL;
	private String UNTERN;
	private String STILL_KZ;
	String DAT_SEND_ONL;
	private String TEL_TRAPO;
	private String FAX_TRAPO;
	private String EMAIL_TRAPO;
	private String DEALER_TYPE;
	private String IS_RETAIL;
	private String IS_WHOLES;
	private String GPS_X;
	private String GPS_Y;
	private String REGION;
	private String DSC_LEV_SMART;
	private String DSC_LEV_MB;
	private String DSC_LEV_TRUCK;
	private String DSC_LEV_VAN;
	// private String SUB_TYP;
	private String MPC_NR;
	private String GSSN_ID;
	private String GSSN_TIMEST;
	private String MAN_PFLEGE;
	private String PART_TRAPO;
	private String CPO;
	private String IS_OWN_RETAIL;
	private String MASTER_SO_NR;
	private String RELATED_TO_GSSN_ID;
	private String TAX_ID;
	private String VAT_NO;
	private String DEBITOR_ACCOUNT;
	private V0BRB172Key key;
	public V0BRB172Type(){
		
	}

	public V0BRB172Type(V0BRB172Key key, String sO_ART, String fIRMA,
			String fIRMA2, String fIRMA3, String oRT, String pLZ,
			String sTRASSE, String pOSTFACH, String tEL, String fAX,
			String tELEX, String tEL_PKW, String tEL_NFZ, String fAX_PKW,
			String fAX_NFZ, String pART_PKW, String pART_NFZ, String pLZ_P,
			String pASSWORT, String eMAIL, String uRL, String eMAIL_PKW,
			String eMAIL_NFZ, String r2R, String q_STANDARD,String dAT_SEND,
			String wW_PASSWORT, String rETAIL, String uNTERN, String sTILL_KZ,
			String dAT_SEND_ONL, String tEL_TRAPO, String fAX_TRAPO,
			String eMAIL_TRAPO, String dEALER_TYPE, String iS_RETAIL,
			String iS_WHOLES, String gPS_X, String gPS_Y, String rEGION,
			String dSC_LEV_SMART, String dSC_LEV_MB, String dSC_LEV_TRUCK,
			String dSC_LEV_VAN, String sUB_TYP, String mPC_NR, String gSSN_ID,
			String gSSN_TIMEST, String mAN_PFLEGE, String pART_TRAPO,
			String cPO, String iS_OWN_RETAIL, String mASTER_SO_NR,
			String rELATED_TO_GSSN_ID,String tAX_ID, String vAT_NO,
			String dEBITOR_ACCOUNT) {
		super();
		this.key = key;
		this.SO_ART = sO_ART;
		this.FIRMA = fIRMA;
		this.FIRMA2 = fIRMA2;
		this.FIRMA3 = fIRMA3;
		this.ORT = oRT;
		this.PLZ = pLZ;
		this.STRASSE = sTRASSE;
		this.POSTFACH = pOSTFACH;
		this.TEL = tEL;
		this.FAX = fAX;
		this.TELEX = tELEX;
		this.TEL_PKW = tEL_PKW;
		this.TEL_NFZ = tEL_NFZ;
		this.FAX_PKW = fAX_PKW;
		this.FAX_NFZ = fAX_NFZ;
		this.PART_PKW = pART_PKW;
		this.PART_NFZ = pART_NFZ;
		this.PLZ_P = pLZ_P;
		this.PASSWORT = pASSWORT;
		this.EMAIL = eMAIL;
		this.URL = uRL;
		this.EMAIL_PKW = eMAIL_PKW;
		this.EMAIL_NFZ = eMAIL_NFZ;
		this.R2R = r2R;
		this.Q_STANDARD = q_STANDARD;
		this.DAT_SEND = dAT_SEND;
		this.WW_PASSWORT = wW_PASSWORT;
		this.RETAIL = rETAIL;
		this.UNTERN = uNTERN;
		this.STILL_KZ = sTILL_KZ;
		this.DAT_SEND_ONL = DEFAULT_TS;
		this.TEL_TRAPO = tEL_TRAPO;
		this.FAX_TRAPO = fAX_TRAPO;
		this.EMAIL_TRAPO = eMAIL_TRAPO;
		this.DEALER_TYPE = dEALER_TYPE;
		this.IS_RETAIL = iS_RETAIL;
		this.IS_WHOLES = iS_WHOLES;
		this.GPS_X = gPS_X;
		this.GPS_Y = gPS_Y;
		this.REGION = rEGION;
		this.DSC_LEV_SMART = dSC_LEV_SMART;
		this.DSC_LEV_MB = dSC_LEV_MB;
		this.DSC_LEV_TRUCK = dSC_LEV_TRUCK;
		this.DSC_LEV_VAN = dSC_LEV_VAN;
		this.MPC_NR = mPC_NR;
		this.GSSN_ID = gSSN_ID;
		this.GSSN_TIMEST = DEFAULT_TS;
		this.MAN_PFLEGE = mAN_PFLEGE;
		this.PART_TRAPO = pART_TRAPO;
		this.CPO = cPO;
		this.IS_OWN_RETAIL = iS_OWN_RETAIL;
		this.MASTER_SO_NR = mASTER_SO_NR;
		this.RELATED_TO_GSSN_ID = rELATED_TO_GSSN_ID;
		this.TAX_ID = tAX_ID;
		this.VAT_NO = vAT_NO;
		this.DEBITOR_ACCOUNT = dEBITOR_ACCOUNT;

	}

	@Override
	public String generate(Sheet sheet, String folder, String str, String uStr)
			throws Exception {
		SQLWriter fileWriterV0BRB172EU;
		SQLWriter fileWriterV0BRB172UX;
		fileWriterV0BRB172EU = new SQLWriter();
		fileWriterV0BRB172UX = new SQLWriter();

		fileWriterV0BRB172EU.openFile(folder + '\\'
				+ SQLWriter.FILENAME_B172_EU);
		fileWriterV0BRB172UX.openFile(folder + '\\'
				+ SQLWriter.FILENAME_B172_UX);
		String COL_CHANGED;
		String COL_SO_LAND;
		String COL_SO_NR;
		String COL_SO_ART;
		String COL_FIRMA;
		String COL_FIRMA2;
		String COL_FIRMA3;
		String COL_ORT;
		String COL_PLZ;
		String COL_STRASSE;
		String COL_POSTFACH;
		String COL_TEL;
		String COL_FAX;
		String COL_TELEX;
		String COL_TEL_PKW;
		String COL_TEL_NFZ;
		String COL_FAX_PKW;
		String COL_FAX_NFZ;
		String COL_PART_PKW;
		String COL_PART_NFZ;
		String COL_PLZ_P;
		String COL_PASSWORT;
		String COL_EMAIL;
		String COL_URL;
		String COL_EMAIL_PKW;
		String COL_EMAIL_NFZ;
		String COL_R2R;
		String COL_Q_STANDARD;
		String COL_DAT_SEND;
		String COL_WW_PASSWORT;
		String COL_RETAIL;
		String COL_UNTERN;
		String COL_STILL_KZ;
		String COL_DAT_SEND_ONL;
		String COL_TEL_TRAPO;
		String COL_FAX_TRAPO;
		String COL_EMAIL_TRAPO;
		String COL_DEALER_TYPE;
		String COL_IS_RETAIL;
		String COL_IS_WHOLES;
		String COL_GPS_X;
		String COL_GPS_Y;
		String COL_REGION;
		String COL_DSC_LEV_SMART;
		String COL_DSC_LEV_MB;
		String COL_DSC_LEV_TRUCK;
		String COL_DSC_LEV_VAN;
		String COL_SUB_TYP;
		String COL_MPC_NR;
		String COL_GSSN_ID;
        String COL_GSSN_TIMEST;
		String COL_MAN_PFLEGE;
		String COL_PART_TRAPO;
		String COL_CPO;
		String COL_IS_OWN_RETAIL;
		String COL_MASTER_SO_NR;
		String COL_RELATED_TO_GSSN_ID;
		String COL_TAX_ID;
		String COL_VAT_NO;
		String COL_DEBITOR_ACCOUNT;
		V0BRB172Type b172Type;
		V0BRB172Key b172key;
		Row row;
		SQLStatment sqlid;
		sqlid = new SQLStatment();
		sqlid.addFragment("SET CURRENT SQLID='" + str + "';");
		sqlid.addFragment(SQLWriter.NEWLINE);
		fileWriterV0BRB172EU.write(sqlid);
		sqlid = new SQLStatment();
		sqlid.addFragment("SET CURRENT SQLID='" + uStr + "';");
		sqlid.addFragment(SQLWriter.NEWLINE);
		fileWriterV0BRB172UX.write(sqlid);
		int active_row = 1;
		int action;
		int rows_ignored = 0;
		int row_deleted = 0;
		int row_inserted = 0;
		int row_count = 0;
		while (true) {
			row = sheet.getRow(active_row);
			if (isRowTheLastRow(row)) {

				fileWriterV0BRB172UX.write(commitStatment());
				fileWriterV0BRB172EU.write(commitStatment());

				break;
			}

			COL_CHANGED = getValueOfStringCell(row.getCell(COL_TABLE_CHANGED));
			action = checkAction(COL_CHANGED);
			if (action == ACTION_ERROR) {
				messages = "Fehler: Die (Steuer-)Zelle "
						+ getStringPos(row.getCell(COL_TABLE_CHANGED))
						+ " muss einen der folgenden Werte enthalten:\n";
				messages += "Loeschen: 'D'\n";
				messages += "Loeschen und Einfuegen: 'I'\n";
				messages += "Keine Aktion: ''\n";
				return messages;
			}

			if (action != ACTION_NONE) {

				COL_SO_LAND = getValueOfStringCell(row
						.getCell(COL_B172_SO_LAND));
				COL_SO_NR = getValueOfStringCell(row.getCell(COL_B172_SO_NR));
				COL_SO_ART = getValueOfStringCell(row.getCell(COL_B172_SO_ART));
				COL_FIRMA = getValueOfStringCell(row.getCell(COL_B172_FIRMA));
				COL_FIRMA2 = getValueOfStringCell(row.getCell(COL_B172_FIRMA2));
				COL_FIRMA3 = getValueOfStringCell(row.getCell(COL_B172_FIRMA3));
				COL_ORT = getValueOfStringCell(row.getCell(COL_B172_ORT));
				COL_PLZ = getValueOfStringCell(row.getCell(COL_B172_PLZ));
				COL_STRASSE = getValueOfStringCell(row
						.getCell(COL_B172_STRASSE));
				COL_POSTFACH = getValueOfStringCell(row
						.getCell(COL_B172_POSTFACH));
				COL_TEL = getValueOfStringCell(row.getCell(COL_B172_TEL));
				COL_FAX = getValueOfStringCell(row.getCell(COL_B172_FAX));
				COL_TELEX = getValueOfStringCell(row.getCell(COL_B172_TELEX));
				COL_TEL_PKW = getValueOfStringCell(row
						.getCell(COL_B172_TEL_PKW));
				COL_TEL_NFZ = getValueOfStringCell(row
						.getCell(COL_B172_TEL_NFZ));
				COL_FAX_PKW = getValueOfStringCell(row
						.getCell(COL_B172_FAX_PKW));
				COL_FAX_NFZ = getValueOfStringCell(row
						.getCell(COL_B172_FAX_NFZ));
				COL_PART_PKW = getValueOfStringCell(row
						.getCell(COL_B172_PART_PKW));
				COL_PART_NFZ = getValueOfStringCell(row
						.getCell(COL_B172_PART_NFZ));
				COL_PLZ_P = getValueOfStringCell(row.getCell(COL_B172_PLZ_P));
				COL_PASSWORT = getValueOfStringCell(row
						.getCell(COL_B172_PASSWORT));
				COL_EMAIL = getValueOfStringCell(row.getCell(COL_B172_EMAIL));
				COL_URL = getValueOfStringCell(row.getCell(COL_B172_URL));
				COL_EMAIL_PKW = getValueOfStringCell(row
						.getCell(COL_B172_EMAIL_PKW));
				COL_EMAIL_NFZ = getValueOfStringCell(row
						.getCell(COL_B172_EMAIL_NFZ));
				COL_R2R = getValueOfStringCell(row.getCell(COL_B172_R2R));
				COL_Q_STANDARD = getValueOfStringCell(row
						.getCell(COL_B172_Q_STANDARD));
			  COL_DAT_SEND = getValueOfStringCell(row
			 .getCell(COL_B172_DAT_SEND));
				COL_WW_PASSWORT = getValueOfStringCell(row
						.getCell(COL_B172_WW_PASSWORT));
				COL_RETAIL = getValueOfStringCell(row.getCell(COL_B172_RETAIL));
				COL_UNTERN = getValueOfStringCell(row.getCell(COL_B172_UNTERN));
				COL_STILL_KZ = getValueOfStringCell(row
						.getCell(COL_B172_STILL_KZ));
				COL_DAT_SEND_ONL = getValueOfStringCell(row
						.getCell(COL_B172_DAT_SEND_ONL));
				COL_TEL_TRAPO = getValueOfStringCell(row
						.getCell(COL_B172_TEL_TRAPO));
				COL_FAX_TRAPO = getValueOfStringCell(row
						.getCell(COL_B172_FAX_TRAPO));
				COL_EMAIL_TRAPO = getValueOfStringCell(row
						.getCell(COL_B172_EMAIL_TRAPO));
				COL_DEALER_TYPE = getValueOfStringCell(row
						.getCell(COL_B172_DEALER_TYPE));
				COL_IS_RETAIL = getValueOfStringCell(row
						.getCell(COL_B172_IS_RETAIL));
				COL_IS_WHOLES = getValueOfStringCell(row
						.getCell(COL_B172_IS_WHOLES));
				COL_GPS_X = getValueOfStringCell(row.getCell(COL_B172_GPS_X));
				COL_GPS_Y = getValueOfStringCell(row.getCell(COL_B172_GPS_Y));
				COL_REGION = getValueOfStringCell(row.getCell(COL_B172_REGION));
				COL_DSC_LEV_SMART = getValueOfStringCell(row
						.getCell(COL_B172_DSC_LEV_SMART));
				COL_DSC_LEV_MB = getValueOfStringCell(row
						.getCell(COL_B172_DSC_LEV_MB));
				COL_DSC_LEV_TRUCK = getValueOfStringCell(row
						.getCell(COL_B172_DSC_LEV_TRUCK));
				COL_DSC_LEV_VAN = getValueOfStringCell(row
						.getCell(COL_B172_DSC_LEV_VAN));
				COL_SUB_TYP = getValueOfStringCell(row
						.getCell(COL_B172_SUB_TYP));
				COL_MPC_NR = getValueOfStringCell(row.getCell(COL_B172_MPC_NR));
				COL_GSSN_ID = getValueOfStringCell(row
						.getCell(COL_B172_GSSN_ID));
				COL_GSSN_TIMEST = getValueOfStringCell(row
						.getCell(COL_B172_GSSN_TIMEST));
				COL_MAN_PFLEGE = getValueOfStringCell(row
						.getCell(COL_B172_MAN_PFLEGE));
				COL_PART_TRAPO = getValueOfStringCell(row
						.getCell(COL_B172_PART_TRAPO));
				COL_CPO = getValueOfStringCell(row.getCell(COL_B172_CPO));
				COL_IS_OWN_RETAIL = getValueOfStringCell(row
						.getCell(COL_B172_IS_OWN_RETAIL));
				COL_MASTER_SO_NR = getValueOfStringCell(row
						.getCell(COL_B172_MASTER_SO_NR));
				COL_RELATED_TO_GSSN_ID = getValueOfStringCell(row
						.getCell(COL_B172_RELATED_TO_GSSN_ID));
				COL_TAX_ID = getValueOfStringCell(row.getCell(COL_B172_TAX_ID));
				COL_VAT_NO = getValueOfStringCell(row.getCell(COL_B172_VAT_NO));
				COL_DEBITOR_ACCOUNT = getValueOfStringCell(row
						.getCell(COL_B172_DEBITOR_ACCOUNT));

				b172key = new V0BRB172Key(COL_SO_LAND, COL_SO_NR, COL_SUB_TYP);

				b172Type = new V0BRB172Type(b172key, COL_SO_ART, COL_FIRMA,
						COL_FIRMA2, COL_FIRMA3, COL_ORT, COL_PLZ, COL_STRASSE,
						COL_POSTFACH, COL_TEL, COL_FAX, COL_TELEX, COL_TEL_PKW,
						COL_TEL_NFZ, COL_FAX_PKW, COL_FAX_NFZ, COL_PART_PKW,
						COL_PART_NFZ, COL_PLZ_P, COL_PASSWORT, COL_EMAIL,
						COL_URL, COL_EMAIL_PKW, COL_EMAIL_NFZ, COL_R2R,
						COL_Q_STANDARD,COL_DAT_SEND, COL_WW_PASSWORT, COL_RETAIL,
						COL_UNTERN, COL_STILL_KZ, COL_DAT_SEND_ONL,
						COL_TEL_TRAPO, COL_FAX_TRAPO, COL_EMAIL_TRAPO,
						COL_DEALER_TYPE, COL_IS_RETAIL, COL_IS_WHOLES,
						COL_GPS_X, COL_GPS_Y, COL_REGION, COL_DSC_LEV_SMART,
						COL_DSC_LEV_MB, COL_DSC_LEV_TRUCK, COL_DSC_LEV_VAN,
						COL_SUB_TYP, COL_MPC_NR, COL_GSSN_ID,COL_GSSN_TIMEST, COL_MAN_PFLEGE,
						COL_PART_TRAPO, COL_CPO, COL_IS_OWN_RETAIL,
						COL_MASTER_SO_NR, COL_RELATED_TO_GSSN_ID, COL_TAX_ID,
						COL_VAT_NO, COL_DEBITOR_ACCOUNT);

				fileWriterV0BRB172EU.write(b172Type.createSQLDescription());
				fileWriterV0BRB172EU.write(b172Type.createSQLDeleteStatment());

				if (action == ACTION_INSERT_AND_DELETE)
					fileWriterV0BRB172EU.write(b172Type
							.createSQLStatment(false));

				fileWriterV0BRB172UX.write(b172Type.createSQLDescription());
				fileWriterV0BRB172UX.write(b172Type.createSQLDeleteStatment());

				if (action == ACTION_INSERT_AND_DELETE)
					fileWriterV0BRB172UX
							.write(b172Type.createSQLStatment(true));
				row_count++;

				if (row_count % 250 == 0) {
					fileWriterV0BRB172EU.write(commitStatment());

					fileWriterV0BRB172UX.write(commitStatment());
				}

			}

			if (action == ACTION_NONE)
				rows_ignored++;

			if (action == ACTION_DELETE)
				row_deleted++;

			if (action == ACTION_INSERT_AND_DELETE)
				row_inserted++;

			active_row++;
		}
		messages = "Zeilen verarbeitet: " + (active_row - 1) + "\n";
		messages += "Zeilen ignoriert: " + rows_ignored + "\n";
		messages += "Zeilen geloescht: " + row_deleted + "\n";
		messages += "Zeilen eingefuegt: " + row_inserted + "\n";

		fileWriterV0BRB172EU.close();
		fileWriterV0BRB172UX.close();

		return messages;
	}

	@Override
	public String getCellStyleStringRep(int type) {
		switch (type) {
		case Cell.CELL_TYPE_STRING:
			return "TEXT";
		case Cell.CELL_TYPE_NUMERIC:
			return "ZAHL";
		case Cell.CELL_TYPE_FORMULA:
			return "FORMEL";
		case Cell.CELL_TYPE_BLANK:
			return "LEER";
		default:
			break;
		}
		return "UNBEKANNT";
	}

	@Override
	public int checkAction(String action) {
		if (action == null)
			return ACTION_ERROR;
		String upperAction = action.toUpperCase();
		if (ACTION_NONE_STRING.equals(upperAction))
			return ACTION_NONE;

		if (ACTION_DELETE_STRING.equals(upperAction))
			return ACTION_DELETE;

		if (ACTION_INSERT_AND_DELETE_STRING.equals(upperAction))
			return ACTION_INSERT_AND_DELETE;

		return ACTION_ERROR;
	}

	@Override
	public String colToString(int col) {
		switch (col) {
		case 1:
			return "A";
		case 2:
			return "B";
		case 3:
			return "C";
		case 4:
			return "D";
		case 5:
			return "E";
		case 6:
			return "F";
		case 7:
			return "G";
		case 8:
			return "H";
		case 9:
			return "I";
		case 10:
			return "J";
		case 11:
			return "K";
		case 12:
			return "L";
		case 13:
			return "M";
		case 14:
			return "N";
		case 15:
			return "O";
		case 16:
			return "P";

		default:
			break;
		}
		return "Ausserhalb des Verabreitungsbereich";
	}

	@Override
	public boolean isRowTheLastRow(Row row) {
		if (row == null)
			return true;

		Cell bmCell = row.getCell(COL_B172_SO_LAND);

		if (bmCell == null)
			return true;

		if (bmCell.getCellType() == Cell.CELL_TYPE_BLANK)
			return true;

		if (bmCell.getCellType() == Cell.CELL_TYPE_STRING) {
			String s = getValueOfStringCell(row.getCell(1));
			if (s == null)
				return true;
			if (!s.equals(""))
				return false;
		}
		return true;
	}

	@Override
	public String getValueOfStringCell(Cell cell) throws InputMismatchException {
		String value = new String("");

		if (cell == null)
			return value;

		if (cell.getCellType() == Cell.CELL_TYPE_BLANK)
			return new String("");

		if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
			value = cell.getStringCellValue();

		} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			int i = (int) cell.getNumericCellValue();
			value = String.valueOf(i);
		} else {
			throw new InputMismatchException("Zelle " + getStringPos(cell)
					+ " ist als " + getCellStyleStringRep(cell.getCellType())
					+ " definiert. Dies kann nicht verarbeit werden.");
		}

		if (value == null)
			return new String("");

		return value.trim();
	}

	@Override
	public String getStringPos(Cell cell) {
		return colToString(cell.getColumnIndex() + 1) + "-"
				+ (cell.getRowIndex() + 1);
	}

	@Override
	public int getValueOfIntCell(Cell cell) throws InputMismatchException {
		if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
			String value = getValueOfStringCell(cell);
			if (value.equals("")) {
				throw new InputMismatchException("Zelle " + getStringPos(cell)
						+ " muss einen (Numerischen) Wert enthalten");
			}
			return Integer.valueOf(value).intValue();
		}

		checkCellStyle(cell, Cell.CELL_TYPE_NUMERIC);

		Double d = cell.getNumericCellValue();
		return d.intValue();
	}

	@Override
	public void checkCellStyle(Cell cell, int type)
			throws InputMismatchException {
		if (cell.getCellType() == type)
			return;

		throw new InputMismatchException("Zelle " + getStringPos(cell)
				+ " muss als " + getCellStyleStringRep(type)
				+ " definiert sein.\n" + "Zelle " + getStringPos(cell)
				+ " ist als " + getCellStyleStringRep(cell.getCellType()) + "("
				+ cell.getCellType() + ") definiert"

		);

	}

	@Override
	public SQLStatment createSQLStatment(boolean uniCode) {
		SQLStatment sql = new SQLStatment();

		sql.addFragment("INSERT INTO V0BRB172 ");
		sql.addFragment("(B172_SO_LAND, ");
		sql.addFragment("B172_SO_NR, ");
		sql.addFragment("B172_SO_ART, ");
		sql.addFragment("B172_FIRMA, ");
		sql.addFragment("B172_FIRMA2, ");
		sql.addFragment("B172_FIRMA3, ");
		sql.addFragment("B172_ORT, ");
		sql.addFragment("B172_PLZ, ");
		sql.addFragment("B172_STRASSE, ");
		sql.addFragment("B172_POSTFACH, ");
		sql.addFragment("B172_TEL, ");
		sql.addFragment("B172_FAX, ");
		sql.addFragment("B172_TELEX, ");
		sql.addFragment("B172_TEL_PKW, ");
		sql.addFragment("B172_TEL_NFZ, ");
		sql.addFragment("B172_FAX_PKW, ");
		sql.addFragment("B172_FAX_NFZ, ");
		sql.addFragment("B172_PART_PKW, ");
		sql.addFragment("B172_PART_NFZ, ");
		sql.addFragment("B172_PLZ_P, ");
		sql.addFragment("B172_PASSWORT, ");
		sql.addFragment("B172_EMAIL, ");
		sql.addFragment("B172_URL, ");
		sql.addFragment("B172_EMAIL_PKW, ");
		sql.addFragment("B172_EMAIL_NFZ, ");
		sql.addFragment("B172_R2R, ");
		sql.addFragment("B172_Q_STANDARD, ");
		sql.addFragment("B172_DAT_SEND, ");
		sql.addFragment("B172_WW_PASSWORT, ");
		sql.addFragment("B172_RETAIL, ");
		sql.addFragment("B172_UNTERN, ");
		sql.addFragment("B172_STILL_KZ, ");
		sql.addFragment("B172_DAT_SEND_ONL, ");
		sql.addFragment("B172_TEL_TRAPO, ");
		sql.addFragment("B172_FAX_TRAPO, ");
		sql.addFragment("B172_EMAIL_TRAPO, ");
		sql.addFragment("B172_DEALER_TYPE, ");
		sql.addFragment("B172_IS_RETAIL, ");
		sql.addFragment("B172_IS_WHOLES, ");
		sql.addFragment("B172_GPS_X, ");
		sql.addFragment("B172_GPS_Y, ");
		sql.addFragment("B172_REGION, ");
		sql.addFragment("B172_DSC_LEV_SMART, ");
		sql.addFragment("B172_DSC_LEV_MB, ");
		sql.addFragment("B172_DSC_LEV_TRUCK, ");
		sql.addFragment("B172_DSC_LEV_VAN, ");
		sql.addFragment("B172_SUB_TYP, ");
		sql.addFragment("B172_MPC_NR, ");
		sql.addFragment("B172_GSSN_ID, ");
		sql.addFragment("B172_GSSN_TIMEST, ");
		sql.addFragment("B172_MAN_PFLEGE, ");
		sql.addFragment("B172_PART_TRAPO, ");
		sql.addFragment("B172_CPO, ");
		sql.addFragment("B172_IS_OWN_RETAIL, ");
		sql.addFragment("B172_MASTER_SO_NR, ");
		sql.addFragment("B172_RELATED_TO_GSSN_ID, ");
		sql.addFragment("B172_TAX_ID, ");
		sql.addFragment("B172_VAT_NO, ");
		sql.addFragment("B172_DEBITOR_ACCOUNT) ");
		sql.addFragment("VALUES (");
		sql.addValue(this.key.getSO_LAND(), false);
		sql.addValue(this.key.getSO_NR(), false);
		sql.addValue(this.SO_ART, false);
		if (uniCode)
			sql.addUXValue(this.FIRMA, false);
		else
			sql.addXValue(this.FIRMA, false);

		if (uniCode)
			sql.addUXValue(this.FIRMA2, false);
		else
			sql.addXValue(this.FIRMA2, false);
		if (uniCode)
			sql.addUXValue(this.FIRMA3, false);
		else
			sql.addXValue(this.FIRMA3, false);
		if (uniCode)
			sql.addUXValue(this.ORT, false);
		else
			sql.addXValue(this.ORT, false);
		sql.addValue(this.PLZ, false);
		if (uniCode)
			sql.addUXValue(this.STRASSE, false);
		else
			sql.addXValue(this.STRASSE, false);
		sql.addValue(this.POSTFACH, false);
		sql.addValue(this.TEL, false);
		sql.addValue(this.FAX, false);
		sql.addValue(this.TELEX, false);
		sql.addValue(this.TEL_PKW, false);
		sql.addValue(this.TEL_NFZ, false);
		sql.addValue(this.FAX_PKW, false);
		sql.addValue(this.FAX_NFZ, false);
		if (uniCode)
			sql.addUXValue(this.PART_PKW, false);
		else
			sql.addXValue(this.PART_PKW, false);
		if (uniCode)
			sql.addUXValue(this.PART_NFZ, false);
		else
			sql.addXValue(this.PART_NFZ, false);
		sql.addValue(this.PLZ_P, false);
		if (uniCode)
			sql.addUXValue(this.PASSWORT, false);
		else
			sql.addXValue(this.PASSWORT, false);
		if (uniCode)
			sql.addUXValue(this.EMAIL, false);
		else
			sql.addXValue(this.EMAIL, false);
		if (uniCode)
			sql.addUXValue(this.URL, false);
		else
			sql.addXValue(this.URL, false);
		if (uniCode)
			sql.addUXValue(this.EMAIL_PKW, false);
		else
			sql.addXValue(this.EMAIL_PKW, false);
		if (uniCode)
			sql.addUXValue(this.EMAIL_NFZ, false);
		else
			sql.addXValue(this.EMAIL_NFZ, false);
		sql.addValue(this.R2R, false);
		sql.addValue(this.Q_STANDARD, false);
		sql.addValue(this.DAT_SEND, false);
		if (uniCode)
			sql.addUXValue(this.WW_PASSWORT, false);
		else
			sql.addXValue(this.WW_PASSWORT, false);
		sql.addValue(this.RETAIL, false);
		sql.addValue(this.UNTERN, false);
		sql.addValue(this.STILL_KZ, false);
		sql.addNotQuetedValue(this.DAT_SEND_ONL, false);
		sql.addValue(this.TEL_TRAPO, false);
		sql.addValue(this.FAX_TRAPO, false);
		if (uniCode)
			sql.addUXValue(this.EMAIL_TRAPO, false);
		else
			sql.addXValue(this.EMAIL_TRAPO, false);
		sql.addValue(this.DEALER_TYPE, false);
		sql.addValue(this.IS_RETAIL, false);
		sql.addValue(this.IS_WHOLES, false);
		sql.addValue(this.GPS_X, false);
		sql.addValue(this.GPS_Y, false);
		if (uniCode)
			sql.addUXValue(this.REGION, false);
		else
			sql.addXValue(this.REGION, false);
		sql.addValue(this.DSC_LEV_SMART, false);
		sql.addValue(this.DSC_LEV_MB, false);
		sql.addValue(this.DSC_LEV_TRUCK, false);
		sql.addValue(this.DSC_LEV_VAN, false);
		sql.addValue(this.key.getSUB_TYP(), false);
		sql.addValue(this.MPC_NR, false);
		sql.addValue(this.GSSN_ID, false);
		sql.addNotQuetedValue(this.GSSN_TIMEST, false);
		sql.addValue(this.MAN_PFLEGE, false);
		if (uniCode)
			sql.addUXValue(this.PART_TRAPO, false);
		else
			sql.addXValue(this.PART_TRAPO, false);
		sql.addValue(this.CPO, false);
		sql.addValue(this.IS_OWN_RETAIL, false);
		sql.addValue(this.MASTER_SO_NR, false);
		sql.addValue(this.RELATED_TO_GSSN_ID, false);
		sql.addValue(this.TAX_ID, false);
		sql.addValue(this.VAT_NO, false);
		sql.addValue(this.DEBITOR_ACCOUNT, true);
		sql.addFragment(SQLWriter.NEWLINE);
		return sql;
	}

	@Override
	public SQLStatment createSQLDeleteStatment() {
		SQLStatment sql = new SQLStatment();
		sql.addFragment("DELETE FROM V0BRB172 ");
		sql.addFragment("WHERE ");
		sql.addFragment("B172_SO_LAND = '" + key.getSO_LAND() + "' ");
		sql.addFragment("AND B172_SO_NR = '" + key.getSO_NR() + "' ");
		sql.addFragment("AND B172_SUB_TYP = '" + key.getSUB_TYP() + "' ;");
		sql.addFragment(SQLWriter.NEWLINE);
		return sql;
	}

	@Override
	public SQLStatment createSQLDescription() {
		SQLStatment sql = new SQLStatment();
		sql.addFragment("--" + this.key.getSO_NR());
		sql.addFragment("------------------------------------------------------------------------");
		return sql;
	}

	@Override
	public SQLStatment commitStatment() {
		SQLStatment commit = new SQLStatment();
		commit.addFragment("COMMIT;" + SQLWriter.NEWLINE);
		return commit;
	}

}
